package com.yixun.qfbao.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import com.yixun.qfbao.apidto.*;
import com.yixun.qfbao.hander.*;
import com.yixun.qfbao.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.yixun.qfbao.apidto.v10dto.EstateDetailVo;
import com.yixun.qfbao.utils.JSONUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
@ResponseBody
@RequestMapping("/openapi")
@Api(tags = "openapi")
public class OpenApiController {

	private static final Logger logger = LoggerFactory.getLogger(ApiController.class);
	@Autowired
	private GetProvinceForOtherHander getProvinceHander;
	@Autowired
	private GetPremisesForOtherHander getPremisesForOtherHander;
	@Autowired
	private AddDistributionPremisesHander addDistributionPremisesHander;
	@Autowired
	private GetPremisesDetailForV10Hander getPremisesDetailForV10Hander;
	@Autowired
	private GetCityForOtherHander getCityForOtherHander;
	@Autowired
	private GetAreaForOtherHander getAreaForOtherHander;
	@Autowired
	private GetPremisesCityHander getPremisesCityHander;
	@Autowired
	private GetPremisesListPageHander getPremisesListPageHander;
	@Autowired
	private AddFlowRecordHander addFlowRecordHander;
	@Autowired
	private GetPremisesPhotoHander getPremisesPhotoHander;
	@Autowired
	private GetPremisesHuxingHander getPremisesHuxingHander;
	@Autowired
	private GetPremisesDynamicHander getPremisesDynamicHander;
	@Autowired
	private MarketingSmsAsyncHander marketingSmsAsyncHander;
	@Autowired
    private UpdateSaleStatusHander updateSaleStatusHander;
	@Autowired
	private ExchangeHousesHander exchangeHousesHander;
	@Autowired
	private NewUpdateSaleStatusHander newUpdateSaleStatusHander;
	@Autowired
	private SendPremisesListHander sendPremisesListHander;
	@Autowired
	private SendVisitListHander sendVisitListHander;
	@Autowired
	private SendIntentionListHander sendIntentionListHander;
	@Autowired
	private UpdateAdviserHander updateAdviserHander;

	/**
	 * 获取楼盘信息
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/getPremises", produces = "application/json")
	public String getPremises(HttpServletRequest request, @RequestBody GetPremisesForOtherReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesForOtherHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremises error: {}", e);
			return null;
		}
	}

	/**
	 * 获取省份
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/getProvince", produces = "application/json")
	public String getProvince(HttpServletRequest request, @RequestBody GetProvinceForOtherReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getProvinceHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getProvince error: {}", e);
			return null;
		}
	}

	/**
	 * 分销审核申请
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/addPremisesAudit", produces = "application/json")
	public String addPremisesAudit(HttpServletRequest request, @RequestBody AddDistributionPremisesReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(addDistributionPremisesHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("addPremisesAudit error: {}", e);
			return null;
		}
	}

	/**
	 * 获取楼盘详情
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/getPremisesDetail", produces = "application/json")
	@ApiOperation(value = "楼盘详情", response = EstateDetailVo.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPremisesDetailForV10ReqVo") })
	public String getPremisesDetail(HttpServletRequest request, @RequestBody GetPremisesDetailForV10ReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesDetailForV10Hander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesDetail error: {}", e);
			return null;
		}
	}

	/**
	 * 获取市列表
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/getCity", produces = "application/json")
	public String getCity(HttpServletRequest request, @RequestBody GetCityForOtherReqVo reqVo) throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getCityForOtherHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getCity error: {}", e);
			return null;
		}
	}

	/**
	 * 获取区、县列表
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@PostMapping(value = "/getArea", produces = "application/json")
	@ApiOperation(value = "获取区、县列表", response = GetAreaForOtherResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetAreaForOtherReqVo") })
	public String getArea(HttpServletRequest request, @RequestBody GetAreaForOtherReqVo reqVo) throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getAreaForOtherHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getArea error: {}", e);
			return null;
		}
	}

	/**
	 * 获取一二手联动楼栋的所有城市
	 * 
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "获取一二手联动楼栋的所有城市", response = GetPremisesCityResDto.class)
	@PostMapping(value = "/getPremisesCity", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPremisesCityReqVo") })
	public String getPremisesCity(HttpServletRequest request, @RequestBody GetPremisesCityReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesCityHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesCity error: {}", e);
			return null;
		}
	}

	/**
	 * 获取分销楼盘列表
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 */
	@ApiOperation(value = "分销楼盘列表", response = GetPremisesListPageResDto.class)
	@PostMapping(value = "/getPremisesPage", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPremisesListPageReqVo") })
	public String getPremisesPage(HttpServletRequest request, @RequestBody GetPremisesListPageReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesListPageHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesPage error: {}", e);
			return null;
		}
	}

	/**
	 * 添加点击量
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@ApiOperation(value = "添加点击量", response = AddFlowRecordResDto.class)
	@PostMapping(value = "/addFlowRecord", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "AddFlowRecordReqVo") })
	public String addFlowRecord(HttpServletRequest request, @RequestBody AddFlowRecordReqVo reqVo) throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(addFlowRecordHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("addFlowRecord error: {}", e);
			return null;
		}
	}

	/**
	 * 获取楼盘相册
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 */
	@ApiOperation(value = "获取楼盘相册", response = GetPremisesPhotoResDto.class)
	@PostMapping(value = "/getPremisesPhoto", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPremisesPhotoReqVo") })
	public String getPremisesPhoto(HttpServletRequest request, @RequestBody GetPremisesPhotoReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesPhotoHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesPhoto error: {}", e);
			return null;
		}
	}

	/**
	 * 获得户型信息
	 * 
	 * @param request
	 * @param reqVo
	 * @return
	 */
	@ApiOperation(value = "获得户型信息", response = GetPremisesHuxingResDto.class)
	@PostMapping(value = "/getPremisesHuxing", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPrmisesHuxingReqVo") })
	public String getPremisesHuxing(HttpServletRequest request, @RequestBody GetPrmisesHuxingReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesHuxingHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesHuxing error: {}", e);
			return null;
		}
	}
	/**
	 * 
	 * 功能描述: <br>
	 *	楼盘动态
	 * @param request
	 * @param reqVo
	 * @return
	 * @throws IOException
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@ApiOperation(value = "获得楼盘动态", response = GetPremisesDynamicResDto.class)
	@PostMapping(value = "/getPremisesDynamicList", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "GetPremisesDynamicReqVo") })
	public String getPremisesDynamic(HttpServletRequest request, @RequestBody GetPremisesDynamicReqVo reqVo)
			throws IOException {
		try {
			return JSONUtil.toJSONStringWithDateFormat(getPremisesDynamicHander.hander(reqVo));
		} catch (Exception e) {
			logger.error("getPremisesDynamicList error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "电话平台回调短信状态通知", response = GetPremisesDynamicResDto.class)
	@PostMapping(value = "/marketingSmsAsync", produces = "application/json")
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "MarketingSmsAsyncReqVo") })
	public String marketingSmsAsync(HttpServletRequest request, @RequestBody MarketingSmsAsyncReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(marketingSmsAsyncHander.hander(reqVo));
		}catch (Exception e){

			return null;
		}
	}

    @ApiOperation(value = "M2请求渠道接口,更新交易状态", response = GetPremisesDynamicResDto.class)
    @ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "UpdateSaleStatusReqVo") })
    @PostMapping(value = "/updateSaleStatus", produces = "application/json")
    public String updateSaleStatus(HttpServletRequest request, @RequestBody UpdateSaleStatusReqVo reqVo){
        try{
            return JSONUtil.toJSONStringWithDateFormat(updateSaleStatusHander.hander(reqVo));
        }catch (Exception e){
            logger.error("updateSaleStatus error: {}", e);
            return null;
        }
    }

	@ApiOperation(value = "M2请求渠道接口,换房", response = ExchangeHousesResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "ExchangeHousesReqVo") })
	@PostMapping(value = "/exchangeHouses", produces = "application/json")
	public String exchangeHouses(HttpServletRequest request, @RequestBody ExchangeHousesReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(exchangeHousesHander.hander(reqVo));
		}catch (Exception e){
			logger.error("exchangeHouses error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "M2请求渠道接口,逆向更新交易状态", response = GetPremisesDynamicResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "UpdateSaleStatusReqVo") })
	@PostMapping(value = "/newUpdateSaleStatus", produces = "application/json")
	public String newUpdateSaleStatus(HttpServletRequest request, @RequestBody UpdateSaleStatusReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(newUpdateSaleStatusHander.hander(reqVo));
		}catch (Exception e){
			logger.error("updateSaleStatus error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "M2请求渠道接口,逆向更改置业顾问", response = GetPremisesDynamicResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "UpdateAdviserReqVo") })
	@PostMapping(value = "/m2ToUpdateAdviser", produces = "application/json")
	public String m2ToUpdateAdviser(HttpServletRequest request, @RequestBody UpdateAdviserReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(updateAdviserHander.hander(reqVo));
		}catch (Exception e){
			logger.error("m2ToUpdateAdviser error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "恒信定时推送，楼盘信息推送", response = SendPremisesListResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "SendReqVo") })
	@PostMapping(value = "/sendPremisesList", produces = "application/json")
	public String sendPremisesList(HttpServletRequest request, @RequestBody SendReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(sendPremisesListHander.hander(reqVo));
		}catch (Exception e){
			logger.error("getSendPremisesList error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "恒信定时推送，到访数据推送", response = SendVisitListResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "SendReqVo") })
	@PostMapping(value = "/sendVisitList", produces = "application/json")
	public String sendVisitList(HttpServletRequest request, @RequestBody SendReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(sendVisitListHander.hander(reqVo));
		}catch (Exception e){
			logger.error("getSendVisitList error: {}", e);
			return null;
		}
	}

	@ApiOperation(value = "恒信定时推送，报备信息推送", response = SendIntentionListResDto.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "reqVo", value = "请求参数", dataType = "SendReqVo") })
	@PostMapping(value = "/sendIntentionList", produces = "application/json")
	public String sendIntentionList(HttpServletRequest request, @RequestBody SendReqVo reqVo){
		try{
			return JSONUtil.toJSONStringWithDateFormat(sendIntentionListHander.hander(reqVo));
		}catch (Exception e){
			logger.error("getSendIntentionList error: {}", e);
			return null;
		}
	}
}
